#ifndef __INTERACTION_H__
#define __INTERACTION_H__

#include "list.h"
#include "ui_device.h"
#include "login_device.h"
#include "ticket_device.h"

#define UI_NUM        (20)

enum ui_options {
    USER_LOGIN = 0,
    USER_REGISTER,
    ADMIN_LOGIN,
    BUY_TICKET,
    RETURN_TICKET,
    MODIFY_USER,
    ADD_TICKET,
    DELETE_TICKET,
    MODIFY_TICKET,
    DELETE_USER,
    USER_MENU,
    MAIN_MENU,
    ADMIN_MENU,
    EXIT
};

enum cue {
    PASSWD_ERROR = 0,
    ID_ERROR,
    ID_NO_MATCH,
    PASSWD_NO_MATCH,
    PHONE_NUM_ERROR,
    CITIZEN_ID_ERROR,
    NAME_ERROR,
    USER_REPEAT,
    NO_TICKET_NUM,
    NO_TRAIN_NUM,
    NO_REPEAT,
    NO_THIS_TRAIN_NUM,
    NO_THIS_TICKET,
    TICKET_INFO_REPEAT,
    TRAIN_NUM_REPEAT,
    PLACE_TIME_REPEAT,
    ORIGIN_PLACE_NO_STRING,
    DESTINATION_NO_STRING,
    DEPARTURE_TIME_FALSE,
    ARRIVAL_TIME_FALSE,
    TRAIN_NUM_NO_NUM,
    PRICE_NO_NUM,
    TICKET_NUM_NO_NUM,
    BUY_TICKET_SUCCESS,
    NO_ERROR,
    MODIFY_FALSE,
    CITIZEN_ID_REPEAT,
    PHONE_NUM_REPEAT,
    RETURN_TICKET_SUCCESS,
    MODIFY_SUCCESS,
    REGISTER_SUCCESS,
    ADD_SUCCESS,
    ADD_FALSE
};

enum error {
    MALLOC_ERROR = 6,
    PARAM_ERROR
};

struct interaction {
    struct list_head user_ticket_head, user_head, ticket_head;
    struct user *current_user;
    struct list_head *current_user_ticket_head;
    struct admin *admin;
    struct ui ui_data[UI_NUM];
};

struct print_ticket_data {
    char origin_place[ORIGIN_PLACE_SIZE];
    char destination[DESTINATION_SIZE];
    char train_number[TRAIN_NUM_SIZE];
    char departure_time[DEPARTURE_TIME];
    char arrival_time[ARRIVAL_TIME];
    char price[PRICE_SIZE];
    char ticket_number[TICKET_NUM_SIZE];
    struct list_head list;
};

struct user_ticket {
    struct list_head someone_ticket_head;
    struct list_head list;
};

typedef int (*func_t)(struct interaction *);

extern int control_func(struct interaction *interaction, func_t *p_func);
extern int user_login(struct interaction *interaction);
extern int user_menu(struct interaction *interaction);
extern int main_menu(struct interaction *interaction);
extern int admin_menu(struct interaction *interaction);
extern int user_register(struct interaction *interaction);
extern int add_ticket(struct interaction *interaction);
extern int buy_ticket(struct interaction *interaction);
extern int admin_login(struct interaction *interaction);
extern int return_ticket(struct interaction *interaction);
extern int modify_user(struct interaction *interaction);
extern int modify_ticket(struct interaction *interaction);

#endif